package cn.zhentao.controller;

import cn.zhentao.pojo.Comment;
import cn.zhentao.pojo.Doctor;
import cn.zhentao.service.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/com")
public class CommentController {
@Autowired
    private CommentService commentService;
//=====zj
@PostMapping("/addcom")
    public void addcom(@RequestBody Comment comment){
    commentService.addcom(comment);
}
//=====sc
@DeleteMapping("/delcom")
    public int delcom(@RequestBody Integer [] cid){
    int delcom = commentService.delcom(cid);
    return delcom;
}
//=====cx
@GetMapping("/findc")
public PageInfo<Comment> findc(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize,@RequestParam String com){
    PageHelper.startPage(pageNum,pageSize);
    List<Comment> findc = commentService.findc(com);
    PageInfo<Comment> commentPageInfo = new PageInfo<>(findc);
    return commentPageInfo;
}
@GetMapping("/finda")
public PageInfo<Comment> finda(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize){
    PageHelper.startPage(pageNum,pageSize);
    List<Comment> findc = commentService.finda();
    PageInfo<Comment> commentPageInfo = new PageInfo<>(findc);
    return commentPageInfo;
}
//=====sc
@DeleteMapping("/del")
    public void del(@RequestParam Integer cid){
    commentService.del(cid);
}
@PostMapping("/findu")
public List<Comment>findu(@RequestParam Integer uid){
    List<Comment> findu = commentService.findu(uid);
    return findu;
}
}
